package org.example.controller;

import org.example.entity.District;
import org.example.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 地区表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-05-09
 */
@Controller
@RestController
@RequestMapping("/regions")
public class DistrictController {

    @Autowired
    private IDistrictService districtService;

    @GetMapping("/provinces")
    public List<District> getProvinces() {
        return districtService.getRegionsByLevel();
    }

    @GetMapping("/cities")
    public List<District> getCities(@RequestParam int district_id, @RequestParam int level) {
        return districtService.getChildrenByParentName(district_id, level);
    }

    @GetMapping("/districts")
    public List<District> getDistricts(@RequestParam int district_id, @RequestParam int level) {
        return districtService.getChildrenByParentName(district_id, level);
    }

}
